package aspect;

import bean.Student;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author HLF
 * @version V1.0
 * @package aspect
 * @date 2021/10/20 14:55
 */
@Aspect
@Component//创建切面类对象
public class MyAspect {

    @Around(value = "execution(* service.impl.StudentServiceImpl.queryAllStudents(..))")
    public Object selectStudentsAround(ProceedingJoinPoint pjp) {
        List<Student> list = null;
        try {
            System.out.println("执行目标方法之前执行，记录时间" +
                    new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
            //执行目标方法
            list = (List<Student>) pjp.proceed();
            System.out.println("执行目标方法之后执行，做事务处理");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return list;
    }
}
